<template>
  <div class="user-container">
    <el-card shadow="never">
      <div class="user-header">
        <el-form :inline="true">
          <el-form-item width="200px">
            <span class="title-label">任务名</span>
            <el-input
                v-model="taskDTO.taskName"
                placeholder="请输入任务名"
                style="width: 120px;float: right"
            ></el-input>
          </el-form-item>
          <el-form-item label="任务状态" >
            <el-select v-model="oneTaskStatus" @change="handleTaskStatusChange" style="width: 100px;">
              <el-option v-for="item in tasKStatus" :key="item.status" :value="item.status">{{item.name}}</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属项目" >
            <el-select v-model="taskVO.projectName" @change="handleProjectChange" style="width: 100px;">
              <el-option v-for="(item,index) in projectList" :key="index" :value="index">{{item.projectName}}</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开始时间">
            <el-col :span="1">
              <el-date-picker type="date" v-model="taskDTO.startDate" style="width: 140px;"></el-date-picker>
            </el-col>
            <el-col class="line" :span="0">-</el-col>
          </el-form-item>
          <el-form-item label="截止时间">
            <el-col :span="1">
              <el-date-picker type="date" v-model="taskDTO.dueDate" style="width: 140px;"></el-date-picker>
            </el-col>
            <el-col class="line" :span="0">-</el-col>
          </el-form-item>
          <el-form-item style="margin-left: 25px">
            <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="handleQuery"
            >搜索
            </el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
              重置
            </el-button>
          </el-form-item>
        </el-form>

        <div class="button-container">
          <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
          >
            新增
          </el-button>
          <el-button
              type="info"
              plain
              icon="el-icon-upload2"
              size="mini"
              disabled
          >
            导入
          </el-button>
          <el-button type="warning" plain icon="el-icon-download" size="mini">
            导出
          </el-button>
        </div>
      </div>

      <div class="user-body">
        <el-table
            :header-cell-style="{ background: '#f8f8f9', color: '#606266' }"
            ref="table"
            row-key="id"
            :data="taskList"
            border
            style="width: 100%"
            size="medium"
            @row-click="checkInfo"

        >
          <el-table-column label="序号" prop="taskId" width="50" align="center">

          </el-table-column>
          <el-table-column
              prop="taskName"
              label="任务名"
              align="center"
              width="150"
          >
          </el-table-column>
          <el-table-column label="开始时间" align="center"  width="160">
            <template slot-scope="scope">
              <span>{{ scope.row.startDate | dateFilter }}</span>
            </template>
          </el-table-column>
          <el-table-column label="截止时间" align="center"  width="160">
            <template slot-scope="scope">
              <span>{{ scope.row.dueDate | dateFilter }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="priority" label="优先级" align="center" width="65">
          </el-table-column>
          <el-table-column label="状态" align="center" key="enabled" width="65">
            <template slot-scope="scope">
              {{getStatus(scope.row.status)}}
            </template>
          </el-table-column>
          <el-table-column label="上次登录时间" align="center" width="160">
            <template slot-scope="scope">
              <span>{{ scope.row.lastLoginTime | dateFilter }}</span>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" width="160">
            <template slot-scope="scope">
              <span>{{ scope.row.createTime | dateFilter }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="190">
            <template slot-scope="scope" v-if="scope.row.username != 'admin'">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click.stop="handleUpdate(scope.row)"
              >
                修改
              </el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click.stop="handleDelete(scope.row)"
              >
                删除
              </el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-d-arrow-right"
                  @click.stop="handleGive(scope.row)"
              >
                分配
              </el-button>

              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-finished"
                  @click.stop="handleProgress(scope.row)"
              >
                进度
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="user-footer">
        <el-pagination
            :page-sizes="[5, 10, 20, 50, 100]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        >
        </el-pagination>
      </div>

    </el-card>
    <!--    查看任务详情对话框-->
    <el-dialog
        :title="dialogTitle"
        width="700px"
        :visible="detailDialogShow"
        :before-close="handleClose"
        disabled="disabled"
    >
      <el-form
          ref="form"
          :model="taskInfo"
          label-width="80px"
          size="mini"
      >
        <el-form-item label="任务名称">
          <el-input v-model="taskInfo.taskName" disabled></el-input>
        </el-form-item>
        <el-form-item label="任务状态">
          <el-select v-model="oneTaskStatus"  disabled>
            <el-option v-for="item in tasKStatus" :key="item.status">{{item.name}}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input v-model="taskVO.niceName" disabled></el-input>
        </el-form-item>
        <el-form-item label="项目编号">
          <el-input v-model="taskInfo.projectId" disabled></el-input>
        </el-form-item>
        <el-form-item label="项目名称">
          <el-input v-model="taskVO.projectName" disabled></el-input>
        </el-form-item>
        <el-form-item label="优先级">
          <el-select v-model="taskInfo.priority" disabled>
            <el-option         v-for="item in priorities"
                               :key="item"
                               :label="item"
                               :value="item">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="父任编号">
          <el-input v-model="taskInfo.parentTaskId" disabled></el-input>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-col :span="11">
            <el-date-picker type="date" v-model="taskInfo.startDate" style="width: 100%;" disabled=""></el-date-picker>
          </el-col>
          <el-col class="line" :span="0">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="taskInfo.startDate" style="width: 100%;" disabled></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="截止时间">
          <el-col :span="11">
            <el-date-picker type="date" v-model="taskInfo.dueDate" style="width: 100%;" disabled></el-date-picker>
          </el-col>
          <el-col class="line" :span="0">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="taskInfo.dueDate" style="width: 100%;" disabled></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-col :span="11">
            <el-date-picker type="date" v-model="taskInfo.createdAt" style="width: 100%;" disabled=""></el-date-picker>
          </el-col>
          <el-col class="line" :span="0">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="taskInfo.createdAt" style="width: 100%;" disabled></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="任务描述">
          <el-input type="textarea" v-model="taskInfo.taskDescription" disabled></el-input>
        </el-form-item>

        <!--        <el-form-item size="large">-->
        <!--          <el-button type="primary" @click="onSubmit">立即创建</el-button>-->
        <!--          <el-button>取消</el-button>-->
        <!--        </el-form-item>-->
      </el-form>
    </el-dialog>

    <!--    修改任务详情框-->
    <el-dialog
        :title="dialogTitle"
        width="700px"
        :visible="updateDialogShow"
        :before-close="handleClose"
    >
      <el-form
          ref="form"
          :model="taskInfo"
          label-width="80px"
          size="mini"
      >
        <el-form-item label="任务名称">
          <el-input v-model="taskInfo.taskName"></el-input>
        </el-form-item>
        <el-form-item label="任务状态">
          <el-select v-model="oneTaskStatus" @change="handleTaskStatusChange">
            <el-option v-for="item in tasKStatus" :key="item.status" :value="item.status">{{item.name}}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input v-model="taskVO.niceName"></el-input>
        </el-form-item>
        <el-form-item label="项目名称">
          <el-select v-model="taskVO.projectName" @change="handleProjectChange">
            <el-option v-for="(item,index) in projectList" :key="index" :value="index">{{item.projectName}}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="优先级">
          <el-select v-model="taskInfo.priority">
            <el-option         v-for="item in priorities"
                               :key="item"
                               :label="item"
                               :value="item">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="父任务">
          <el-select v-model="taskVO.parentTaskName" @change="handleParentTaskChange">
            <el-option v-for="(item,index) in selectTask" :key="index" :value="index">{{item.taskName}}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-col :span="11">
            <el-date-picker type="date" v-model="taskInfo.startDate" style="width: 100%;"></el-date-picker>
          </el-col>
          <el-col class="line" :span="0">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="taskInfo.startDate" style="width: 100%;"></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="截止时间">
          <el-col :span="11">
            <el-date-picker type="date" v-model="taskInfo.dueDate" style="width: 100%;"></el-date-picker>
          </el-col>
          <el-col class="line" :span="0">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="taskInfo.dueDate" style="width: 100%;"></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-col :span="11">
            <el-date-picker type="date" v-model="taskInfo.createdAt" style="width: 100%;"></el-date-picker>
          </el-col>
          <el-col class="line" :span="0">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="taskInfo.createdAt" style="width: 100%;"></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="任务描述">
          <el-input type="textarea" v-model="taskInfo.taskDescription"></el-input>
        </el-form-item>
        <el-form-item size="large">
          <el-button type="primary" @click="onSubmit">{{operation}}</el-button>
          <el-button @click="handleClose">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--    添加任务详情框-->
    <el-dialog
        :title="dialogTitle"
        width="700px"
        :visible="addDialogShow"
        :before-close="handleClose"
    >
      <el-form
          ref="form"
          :model="taskInfo"
          label-width="80px"
          size="mini"
      >
        <el-form-item label="任务名称">
          <el-input v-model="taskInfo.taskName"></el-input>
        </el-form-item>
        <el-form-item label="所属项目">
          <el-select v-model="taskVO.projectName" @change="handleProjectChange">
            <el-option v-for="(item,index) in projectList" :key="index" :value="index">{{item.projectName}}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="优先级">
          <el-select v-model="taskInfo.priority">
            <el-option         v-for="item in priorities"
                               :key="item"
                               :label="item"
                               :value="item">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="父任务">
          <el-select v-model="taskVO.parentTaskName" @change="handleParentTaskChange">
            <el-option v-for="(item,index) in selectTask" :key="index" :value="index">{{item.taskName}}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-col :span="11">
            <el-date-picker type="date" v-model="taskInfo.startDate" style="width: 100%;"></el-date-picker>
          </el-col>
          <el-col class="line" :span="0">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="taskInfo.startDate" style="width: 100%;"></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="截止时间">
          <el-col :span="11">
            <el-date-picker type="date" v-model="taskInfo.dueDate" style="width: 100%;"></el-date-picker>
          </el-col>
          <el-col class="line" :span="0">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="taskInfo.dueDate" style="width: 100%;"></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="任务描述">
          <el-input type="textarea" v-model="taskInfo.taskDescription"></el-input>
        </el-form-item>
        <el-form-item size="large">
          <el-button type="primary" @click="onSubmit">{{operation}}</el-button>
          <el-button @click="handleClose">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--      分配工作组对话框  -->
    <el-dialog
        :title="dialogTitle"
        width="715px"
        :visible="giveDialogShow"
        :before-close="handleClose"
    >
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>任务名：{{taskInfo.taskName}}</span>
        </div>
        <div class="text item">
          {{taskInfo.taskDescription}}
        </div>
      </el-card>
      <div style="text-align: center">
        <el-transfer
            style="text-align: left; display: inline-block"
            v-model="value"
            filterable
            :left-default-checked="[]"
            :right-default-checked="[1,2]"
            :render-content="renderFunc"
            :titles="['待选工作组', '分配工作组']"
            :button-texts="['到左边', '到右边']"
            :format="{
        noChecked: '${total}',
        hasChecked: '${checked}/${total}'
      }"
            @change="handleChangeGroup"
            :data="groupList">
        </el-transfer>
        <el-button type="primary" @click="handleGiveServer">分配</el-button>
        <el-button @click="handleClose">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog
        :title="dialogTitle"
        width="715px"
        :visible="ProgressShow"
        :before-close="handleClose"
    >
    <el-form label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="日报ID：">
             
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日报内容：">
            
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日报状态：">
            
            </el-form-item>
          </el-col>
          
    
        </el-row>
      </el-form>
  
        <span slot="footer" class="dialog-footer">

          <el-button type="primary" v-show ="showButton" @click="submitForm">确定</el-button>


          <el-button @click="handleClose">退出</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getUserList,
  getUserInfoById,
  changeUserEnabled,
  addUser,
  updatePasswordById,
  deleteUserById,
} from "@/api/user.js";
import {
  getAllTask, getTaskDetail, updateTask, addTask, deleteTask
} from "@/api/task.js";
import { getAllRoles, getRoleByUserId, updateUserRole } from "@/api/security";
import { getAllProjects} from "@/api/project";
import { getAllGroup,getGroupOfOneTask,getNotGroupOfOneTask} from "@/api/group";
import { addRelation} from "@/api/groupTask";
import dayjs from "dayjs";
import index from "vuex";

export default {
  name: "Tasklist",

  data() {
    return {
      value: [],
      notSelectValue:[],
      selectValue:[],
      renderFunc(h, option) {
        return <span>{ option.key } - { option.label }</span>;
      },
      //该项目中的可选择的任务
      selectTask:[],
      //操作
      operation:"",
      //任务状态列表
      tasKStatus:[
        {
          status:0,
          name:"已创建"
        },
        {
          status:1,
          name:"已提交"
        },
        {
          status:2,
          name:"待完成"
        },
        {
          status:3,
          name:"待审批"
        },
        {
          status:4,
          name:"已完成"
        },
        {
          status:5,
          name:"已弃用"
        }
      ],
      //单个任务状态
      oneTaskStatus:"",
      //优先级选择
      priorities: Array.from({ length: 10 }, (_, index) => index + 1), // 创建从 1 到 10 的数组
      // 通过此任务去详细查的一个数据
      taskVO:{
        projectName:"",
        //负责人名字
        niceName:"",
        //父任务名字
        parentTaskName:"",
      },
      //所有项目列表
      projectList:{},
      // 搜索条件
      taskDTO:{
        createdAt: "",
        dueDate: "",
        priority: -1,
        startDate: "",
        status: -1,
        taskDescription: "",
        taskId: -1,
        taskManagerId: -1,
        taskName: "",
        projectId:-1,
      },
      taskInfo:{
        taskId: undefined,
        taskName: "",
        taskDescription: "",
        status: -1,
        startDate: "",
        dueDate: "",
        priority: -1,
        projectId: -1,
        taskManagerId: -1,
        parentTaskId: null,
        createdAt: "",
        updatedAt: ""
      },
      // 用户名
      username: "",
      // 当前页数
      curPage: 1,
      // 页面大小
      size: 10,
      // 用户数据
      taskList:[],
      userList: [],
      groupList:[],
      // 用户角色
      roles: [],
      // 当前选中的角色
      roleValue: undefined,
      // 数据条数
      total: 0,
      // 任务详情对话框是否显示
      detailDialogShow: false,
      // 任务更新对话框是否显示
      updateDialogShow: false,
      //添加任务对话框
      addDialogShow: false,
      //分配工作组对话框
      giveDialogShow: false,
      // 对话框标题
      dialogTitle: "",
      // 用户对象
      user: {},
      // 用户更新对象
      userInfo: {
        id: undefined,
        username: "",
        nickName: "",
        email: "",
        csdn: "",
        leetcode: "",
        github: "",
        gitee: "",
        qq: "",
        phone: "",
        description: "",
      },
      // 图片预览
      srcList: [],
      // 分配角色
      dialogRoleShow: false,
      //进度查看对话框
      ProgressShow: false,
      // 用户的角色ID
      roleId: undefined,
      // 当前的用户ID
      userId: undefined,
    };
  },

  mounted() {
    this.getTableData();
    this.getUserRoles();
    this.getProjects();
  },

  methods: {
    // 分配工作组
    handleGiveServer(){
      console.log("选择组");
      console.log("value",this.value);
      // 序列化为JSON字符串
      let jsonString = this.value.join(",")
      console.log(22)
      console.log("string",jsonString)
      addRelation({
        task_id:this.taskInfo.taskId,
        group_id_list:jsonString
      }).then((result)=>{
        this.getTableData();
      })
      this.handleClose();

    },
    handleChangeGroup(value, direction, movedKeys) {
      console.log(value, direction, movedKeys);
      console.log("value",this.value)
    },
    //获取本任务已经分配了的组
    getHaveGiveGroup(){
      console.log("asasas")
      getGroupOfOneTask({
        task_id:1
      }).then((result)=>{
        console.log("已经分配",result)
        this.selectValue= result.list;
        console.log("已经分配2",this.selectValue)
      })
    },
    //获取所有没有这个任务的工作组
    getGroups(){
      console.log("1111")
      getNotGroupOfOneTask({
        task_id:this.taskInfo.taskId
      }).then((result) => {
        this.groupList = result;
        console.log("result", result)
        console.log("groups", this.groupList)
        let groups = this.groupList;
        groups.forEach(group => {
          group.key = group.groupId;
          group.label = group.groupName;
        })
        this.groupList = groups;
        console.log("changeGroup", this.groupList)
      })
    },
    getStatus(status){
      return this.tasKStatus[status].name
    },
    //点击查看任务详情
    checkInfo(row){
      this.dialogTitle = "任务详情"
      this.taskInfo = row
      console.log("taskInfo到这里了",this.taskInfo)
      console.log("row",row)
      // 获取taskVO
      getTaskDetail({
        task_manager_id: this.taskInfo.taskManagerId,
        project_id: this.taskInfo.projectId,
        parent_task_id:this.taskInfo.parentTaskId,
      }).then((result) =>{
        this.taskVO = result
        console.log("taskVO",this.taskVO)
      })
      this.oneTaskStatus = this.getStatus(this.taskInfo.status);
      this.detailDialogShow = true;
    },
    //获取所有任务表格数据

    // 获取表格数据
    getTableData() {
      getAllTask(
          {
            curPage: this.curPage,
            size: this.size,
          },
          {
            createdAt: this.taskDTO.createdAt,
            dueDate: this.taskDTO.dueDate,
            priority: this.taskDTO.priority,
            startDate: this.taskDTO.startDate,
            status: this.taskDTO.status,
            taskDescription: this.taskDTO.taskDescription,
            taskId: this.taskDTO.taskId,
            taskManagerId: this.taskDTO.taskManagerId,
            taskName: this.taskDTO.taskName,
            projectId:this.taskDTO.projectId
          }).then((result) => {
        console.log("taskResuilt",result)
        this.taskList = result.list;
        this.total = result.total;
      });
    },
    // 获取所有角色数据
    getUserRoles() {
      getAllRoles().then((result) => {
        this.roles = result;
      });
    },
    // 点击了查询按钮
    handleQuery() {
      console.log("taskVO2",this.taskDTO)
      this.getTableData();
    },
    // 点击了重置按钮
    resetQuery() {
      this.oneTaskStatus = "";
      this.taskVO={
        projectName:"",
        //负责人名字
        niceName:"",
        //父任务名字
        parentTaskName:"",
      },
      this.taskDTO = {
        createdAt: "",
        dueDate: "",
        priority: -1,
        startDate: "",
        status: -1,
        taskDescription: "",
        taskId: -1,
        taskManagerId: -1,
        taskName: ""
      }
    },
    // 关闭对话框
    handleClose() {
      this.oneTaskStatus = "",
          this.detailDialogShow = false;
      this.updateDialogShow = false;
      this.addDialogShow = false;
      this.giveDialogShow = false;
      this.reset();
    },
    // 刷新表单数据
    reset() {
      // 修改表单标题
      this.dialogTitle = "";
      // 重置表单对象
      this.taskVO={
        projectName:"",
        niceName:"",
        parentTaskName:""
      }
      //重置任务对象
      this.taskInfo = {
        taskId: undefined,
        taskName: "",
        taskDescription: "",
        status: -1,
        startDate: "",
        dueDate: "",
        priority: -1,
        projectId: -1,
        taskManagerId: -1,
        parentTaskId: null,
        createdAt: "",
        updatedAt: ""
      };
      this.groupList = []
      this.value = []
    },
    // 当页面大小发生变化时
    handleSizeChange(val) {
      this.size = val;
      // 重新获取数据
      this.getTableData();
    },
    handleProgress(row){

    },
    //任务状态修改
    handleTaskStatusChange(newValue) {
      // newValue 是 v-model 绑定的值，即 oneTaskStatus 的新值
      console.log('选择的状态:', newValue);
      // 在这里，您可以根据 newValue 做任何您需要的操作，比如发送 API 请求、更新其他数据等
      this.oneTaskStatus = this.getStatus(newValue);
      this.taskInfo.status = newValue;
      this.taskDTO.status = newValue;
    },
    //任务的所属项目的更改
    handleProjectChange(index) {
      this.taskVO.projectName = this.projectList[index].projectName;
      this.taskInfo.projectId = this.projectList[index].projectId;
      this.taskDTO.projectId = this.projectList[index].projectId;
      this.getTask(this.taskInfo.projectId);
    },
    handleParentTaskChange(index){
      this.taskVO.parentTaskName = this.selectTask[index].taskName;
      this.taskInfo.parentTaskId = this.selectTask[index].taskId;
    },
    // 当前页发生变化时
    handleCurrentChange(val) {

      this.curPage = val;
      // 重新获取数据
      this.getTableData();
    },
    //获取带筛选的项目以及项目所包的任务
    getTask(projectId){
      //获取所有项目供筛选
      getAllTask({
        size:1000,
        curPage:1
      },{
        projectId:projectId
      }).then((result)=> {
        this.selectTask = result.list
        console.log("selectTask",this.selectTask)
      })
    },
    //获取所有项目供筛选
    getProjects(){
      getAllProjects({
            size:1000,
            curPage:1
          },
          {}).then((result)=>
      {
        this.projectList = result.list
        console.log("projectList",this.projectList)
      })
    },
    // 点击修改事件
    handleUpdate(row) {
      this.operation = "立即修改"
      this.dialogTitle = "修改任务"
      this.taskInfo = row

      console.log("taskInfo到这里了",this.taskInfo)
      console.log("row",row)

      // 获取taskVO
      getTaskDetail({
        task_manager_id: this.taskInfo.taskManagerId,
        project_id: this.taskInfo.projectId,
        parent_task_id:this.taskInfo.parentTaskId,
      }).then((result) =>{
        this.taskVO = result
        console.log("taskVO",this.taskVO)
      })
      //更新任务待选项
      this.getTask(this.taskInfo.projectId)
      this.oneTaskStatus = this.getStatus(this.taskInfo.status);
      this.updateDialogShow = true;
    },
    // 点击新增事件
    handleAdd() {
      this.getProjects();
      this.operation = "立即添加";
      this.dialogTitle = "添加任务";
      this.addDialogShow = true
      this.reset()
    },
    // 修改用户是否启用状态
    handleStatusChange(row) {
      changeUserEnabled(row.id).then(() => {
        // 刷新表格数据
        this.getTableData();
      });
    },
    //提交表单
    onSubmit(){
      // 如果存在ID则说明为更新操作
      console.log("到过这里帖子",this.taskInfo)
      if (this.taskInfo.taskId) {
        console.log("到过这里1",this.taskInfo)
        updateTask(this.taskInfo).then((result) =>{
          console.log("asdasas")
          // 重新获取数据
          this.getTableData();
        })
      } else {
        console.log("到过这里2",this.taskInfo)
        addTask(this.taskInfo).then((result) => {
          console.log("添加")
          // 重新获取数据
          this.getTableData();
        })
      }
      this.handleClose();
    },
    // 点击确认修改/添加事件
    submitForm() {
      // 如果存在ID则说明为更新操作
      if (this.userInfo.id) {
        this.userInfo.username = this.user.username;
        this.userInfo.nickName = this.user.nickName;
        this.$store
            .dispatch("task/updateTask", { task: this.taskInfo})
            .then(() => {
              // 重新获取数据
              this.getTableData();
            });
      } else {
        this.userInfo.username = this.user.username;
        this.userInfo.nickName = this.user.nickName;
        this.userInfo.roleId = this.roleValue;
        addUser(this.userInfo).then(() => {
          this.getTableData();
        });
      }
      this.handleClose();
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleResetPwd":
          this.handlePasswordOpen(row);
          break;
        case "handleAuthRole":
          this.handleRoleOpen(row);
          break;
        default:
          break;
      }
    },
    // 打开分配角色对话框
    handleRoleOpen(row) {
      this.userId = row.id;
      // 获取当前用户对应的角色
      getRoleByUserId(row.id).then((result) => {
        this.roleId = result;
      });
      this.dialogRoleShow = true;
    },
    // 关闭分配角色对话框
    handleRoleClose() {
      this.roleId = undefined;
      this.dialogRoleShow = false;
    },
    //分配任务给工作组
    handleGive(row){
      this.dialogTitle = "分配任务"
      this.taskInfo = row;
      this.getGroups();
      this.giveDialogShow = true;
    },
    // 点击删除按钮
    handleDelete(row) {
      this.$confirm("确定删除 " + row.username + " 吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
          .then(() => {
            // 执行删除操作
            deleteTask({
              task_id_list:row.taskId
            }).then(() => {
              // 重新获取表格数据
              this.getTableData();
            });
          })
          .catch(() => {});
    },
    // 格式化时间
    dateFormat(date) {
      // 使用 dayjs 处理时间
      return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
    },
    // 图片预览
    preViewImage(val) {
      this.srcList = [];
      this.srcList.push(val);
    },
  },

};
</script>

<style lang="scss" scoped>
.user-container {
  margin-top: 10px;

  .user-header {
    margin-top: 10px;
    padding-left: 15px;

    .title-label {
      font-size: 14px;
      font-weight: 700;
      color: #606266;
      margin-right: 12px;
    }
  }

  .user-body {
    margin: 20px 15px 30px 15px;
    font-size: 5px;
  }

  .user-footer {
    padding-left: 15px;
    margin-top: 40px;
  }
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.box-card {
  width: 100%;
}
</style>